package com.nuliji.service;

import com.nuliji.exception.InsideException;
import com.nuliji.util.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * 统一返回消息
 * Created by gaojie on 2017/5/11.
 */
@Service
public class MessageService {
    private static final Logger logger = LoggerFactory.getLogger(MessageService.class);
    public Response success(Object result){
        logger.debug("success: "+result.toString());
        return new Response(0, "", result);
    }

    public Response error(int status, String message){
        logger.debug("error:" + status + " " + message);
        return new Response(status, message, null);
    }

    public Response exception(InsideException e){
        logger.debug("exception:" + e.getCode() + " " +e.getMessage());
        return new Response(e.getCode(), e.getMessage(), null);
    }
}
